<?php
include ('funct.php');
header('Content-Type: text/html; charset=utf-8');

function _no_pl($tekst)
{
   $tabela = Array(
   //WIN
    "\xb9" => "a", "\xa5" => "A", "\xe6" => "c", "\xc6" => "C",
    "\xea" => "e", "\xca" => "E", "\xb3" => "l", "\xa3" => "L",
    "\xf3" => "o", "\xd3" => "O", "\x9c" => "s", "\x8c" => "S",
    "\x9f" => "z", "\xaf" => "Z", "\xbf" => "z", "\xac" => "Z",
    "\xf1" => "n", "\xd1" => "N",
   //UTF
    "\xc4\x85" => "ą", "\xc4\x84" => "Ą", "\xc4\x87" => "ć", "\xc4\x86" => "Ć",
    "\xc4\x99" => "ę", "\xc4\x98" => "Ę", "\xc5\x82" => "ł", "\xc5\x81" => "Ł",
    "\xc3\xb3" => "ó", "\xc3\x93" => "Ó", "\xc5\x9b" => "ś", "\xc5\x9a" => "Ś",
    "\xc5\xbc" => "ż", "\xc5\xbb" => "Ż", "\xc5\xba" => "ź", "\xc5\xb9" => "Ź",
    "\xc5\x84" => "ń", "\xc5\x83" => "Ń",
   //ISO
    "\xb1" => "a", "\xa1" => "A", "\xe6" => "c", "\xc6" => "C",
    "\xea" => "e", "\xca" => "E", "\xb3" => "l", "\xa3" => "L",
    "\xf3" => "o", "\xd3" => "O", "\xb6" => "s", "\xa6" => "S",
    "\xbc" => "z", "\xac" => "Z", "\xbf" => "z", "\xaf" => "Z",
    "\xf1" => "n", "\xd1" => "N");

   return strtr($tekst,$tabela);
}

$q=$_POST["q"];
#$q = strtolower($q);
if (!$q) return;
$sql="select pac.id, pac.pac_nazwisko, pac.pac_imie, pac.pac_telefon, pac.pac_pesel, sl_firmy.nazwa, pac.stymulator 
from pac left join sl_firmy on pac.platnik = sl_firmy.id
where pac.pac_nazwisko like '"._no_pl($q)."%' and akt=1";

#echo $sql;

$result=mysql_query($sql);
	while($row = mysql_fetch_array($result))
	{
	if ($row['6']<>'') $stym=' &hearts;';	
            $items[$row['0'].'_'.$row['1'].'_'.$row['2']]=$row['1'].'|'.$row['2'].'|'.$row['3'].'|'.$row['4'].'|'.$row['5'].$stym;
            unset($stym);
	}
	#echo '<pre>';
	#print_r($items);
if ($items<>''){
foreach ($items as $key=>$value) {
	#if (strpos(strtolower(_no_pl($key)), $q) !== false) {
		echo "$key|$value\n";
	#}
}
}
?>